package com.itlong.cloud.operate.resource;

import com.itlong.cloud.POJO.DTO.operate.OperateProductTypeGetPageDTO;
import com.itlong.cloud.POJO.DTO.operate.OperateProductTypeSaveDTO;
import com.itlong.cloud.POJO.VO.operate.OperateProductTypeDetailVO;
import com.itlong.cloud.POJO.VO.operate.OperateProductTypeVO;
import com.itlong.cloud.operate.service.IOperateProductTypeService;
import com.itlong.cloud.project.operate.IOperateProductTypeServiceClient;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <desc>
 *      产品型号信息服务暴露接口实现类
 * </desc>
 *
 * @createDate 2017-10-13.
 */
@RestController
public class OperateProductTypeServiceResource implements IOperateProductTypeServiceClient {

    @Autowired
    IOperateProductTypeService iOperateProductTypeService;


    /**
     * <desc>
     * 检测产品型号存在性
     * <desc/>
     *
     * @param typePid 产品型号Pid
     * @return 同型号Pid的个数
     * @author Chunjian.G
     * @createDate 2017-10-26
     */
    @Override
    @RequestMapping(path = "/operate/project/productType/exist", method = {RequestMethod.POST})
    public Integer checkProductExist(@RequestParam(name = "typePid") String typePid) throws Exception {
        return iOperateProductTypeService.checkProductExist(typePid);
    }

    /**
     * <desc>
     * 添加单个产品型号
     * <desc/>
     *
     * @param saveDTO 新增产品型号信息
     * @return
     * @author Chunjian.G
     * @createDate 2017-10-13
     */
    @Override
    @RequestMapping(path = "/operate/project/productType/add", method = {RequestMethod.POST})
    public Integer saveProductType(@RequestBody OperateProductTypeSaveDTO saveDTO) throws Exception {
        Integer res = iOperateProductTypeService.saveProductType(saveDTO);
        return res;
    }

    /**
     * <desc>
     * 更新单个产品型号
     * <desc/>
     *
     * @param updateDTO 产品型号更新信息
     * @return
     * @author Chunjian.G
     * @createDate 2017-10-13
     */
    @Override
    @RequestMapping(path = "/operate/project/productType/update", method = {RequestMethod.POST})
    public Integer updateProductType(@RequestBody OperateProductTypeSaveDTO updateDTO) throws Exception {
        Integer res = iOperateProductTypeService.updateProductType(updateDTO);
        return res;
    }

    /**
     * <desc>
     *      查询是否有项目关联设备类型
     * <desc/>
     *
     * @param typePid 型号ID
     * @return
     * @author Qiang.S
     * @createDate 2018-07-25
     */
    @Override
    @RequestMapping(path = "/operate/project/productType/getProductCount", method = {RequestMethod.POST})
    public Integer getProductCount(@RequestParam(name = "typePid") String typePid) throws Exception {
        Integer res = iOperateProductTypeService.getProductCount(typePid);
        return res;
    }

    /**
     * <desc>
     * 删除产品型号
     * <desc/>
     *
     * @param typePid 型号ID列表
     * @return
     * @author Chunjian.G
     * @createDate 2017-10-13
     */
    @Override
    @RequestMapping(path = "/operate/project/productType/del", method = {RequestMethod.POST})
    public Integer removeProductType(@RequestParam(name = "typePid") String typePid) throws Exception {
        Integer res = iOperateProductTypeService.removeProductType(typePid);
        return res;
    }

    /**
     * <desc>
     * 分页查询产品型号简易信息列表
     * <desc/>
     *
     * @param pageDTO 分页查询参数
     * @return
     * @author Chunjian.G
     * @createDate 2017-10-13
     */
    @Override
    @RequestMapping(path = "/operate/project/productType/getPage", method = {RequestMethod.POST})
    public Page<OperateProductTypeVO> getPage(@RequestBody OperateProductTypeGetPageDTO pageDTO) throws Exception {
        Page<OperateProductTypeVO> page = iOperateProductTypeService.getPage(pageDTO);
        return page;
    }

    /**
     * <desc>
     * 查询单个产品型号详情
     * <desc/>
     *
     * @param typePid 型号ID
     * @return
     * @author Chunjian.G
     * @createDate 2017-10-13
     */
    @Override
    @RequestMapping(name = "/operate/project/productType/getDetail", method = {RequestMethod.POST})
    public OperateProductTypeDetailVO getDetail(@RequestParam(name = "typePid") String typePid) throws Exception {
        OperateProductTypeDetailVO detailVO = iOperateProductTypeService.getDetail(typePid);
        return detailVO;
    }

    /**
     * <desc>
     *      检测是否存在云电梯的产品。
     * <desc/>
     *
     * @param deviceType 设备类型
     * @param typeCode 型号代号
     * @return
     * @author shengen.T
     * @createDate 2018-04-17
     */
    @Override
    @RequestMapping(path = "/operate/project/productType/checkCloudElevatorExist")
    public Integer checkCloudElevatorExist(@RequestParam("deviceType") Integer deviceType, @RequestParam("typeCode") String typeCode) throws Exception{
        return iOperateProductTypeService.checkCloudElevatorExist(deviceType,typeCode);
    }
}
